package com.niit.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;

import com.niit.entity.Course;
import com.niit.entity.CourseDTO;

public interface CourseMapper  {
	@Insert("INSERT INTO COURSE(COURSENAME, MAXCOUNT) "
			+ "VALUES(#{courseName},#{maxCount})")
	void insertOneCourse(@Param("courseName") String courseName, @Param ("maxCount") Integer maxCount);
	
	@Select("SELECT * FROM COURSE  WHERE MAXCOUNT > #{maxCount}")
	List<Course> findByMaxCount(@Param("maxCount") Integer maxCount);
	
	@Select("select a.studentName, c.courseName from (student a left join stucourse b on a.studentID = b.studentFK ) "
			+ "left join course c on b.courseFK= c.ID where a.studentName= #{studentName}")
	List<CourseDTO> findCourseByStudentName(@Param("studentName") String studentName);
	
	@Select("select studentId from student a where a.studentName=#{studentName}")
	Integer getStudentIdByString(@Param("studentName") String studentName);
	@Select("select ID from course b where b.courseName=#{courseName}")
	Integer getCourseIdByString(@Param("courseName") String courseName);
	@Insert("insert into stucourse (courseFK,studentFK) values (#{cfk},#{sfk})")
	void insertStucourse(@Param("cfk") Integer cfk, @Param("sfk") Integer sfk);
}
/*
@Mapper
public interface UserMapper {

    @Select("SELECT * FROM USER WHERE NAME = #{name}")
    User findByName(@Param("name") String name);

    @Insert("INSERT INTO USER(NAME, AGE) VALUES(#{name}, #{age})")
    int insert(@Param("name") String name, @Param("age") Integer age);

}*/